package com.hinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hinner.entity.fenbushi.FbsLineMainDetail;
import com.hinner.entity.fenbushi.vo.FbsLineMainDetailVO;
import com.hinner.mapper.FbsLineMainDetailMapper;
import com.hinner.service.FbsLineMainDetailService;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class FbsLineMainDetailServiceImpl extends ServiceImpl<FbsLineMainDetailMapper, FbsLineMainDetail> implements FbsLineMainDetailService {
    private static final Logger log = LoggerFactory.getLogger(FbsLineMainDetailServiceImpl.class);


    @Override
    public List<FbsLineMainDetailVO> getDetailByJgdwId(String jgdwId) {
        LambdaQueryWrapper<FbsLineMainDetail> wrapper = new LambdaQueryWrapper<FbsLineMainDetail>().eq(StringUtils.isNotEmpty(jgdwId), FbsLineMainDetail::getJgdwId, jgdwId);
        List<FbsLineMainDetail> details = this.list(wrapper);
        if (CollectionUtils.isEmpty(details)) return null;
        List<FbsLineMainDetailVO> list = details.stream().map(item -> {
            FbsLineMainDetailVO vo = new FbsLineMainDetailVO();
            try {
                BeanUtils.copyProperties(vo,item);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            }
            return vo;
        }).collect(Collectors.toList());
        return list;
    }
}
